Xi-Language Reference: Variables

    • The Type Any
    • The Declaration Statement
    Before we continue with our language definition it might be useful to explain the different variable types of Xi. In this chapter I will use several terms that will be defined lateron. If you have problems with some parts, skip them and reread them after you have read the chapters about the expressions and statements.

    The Type Any

    As mentioned earlier an identifier may be the name of a variable. Whenever the user enters a valid identifier that is not followed by a '(' (in that case it will be a function name) Xi will look for a variable with this name. Unlike C Xi will not produce a syntax error if a variable is not found. It will generate a new local variable of type Any (the nearest equivalent in C may be a pointer to void).

    A variable of type Any can store any possible types of information. To be more precise: Internally the type of an Any-type variable will change every time it is used. For example: If you set an Any-type variable to an integer value the internal type of this variable will be of type Int. If you multiply this variable with a floating-point number the internal type will change to Float or Double.

    The main purpose of the Any-type variables is to allow the user an easy way of declaring new variables. He doesn't need to bother with declaration statements or stuff like that he only uses the variable at any point. In 99.9 percent the result will be the expected. If you are interested in a strict type-checking like iiin C or Pascal, the type Any is useless and you should read the next section.

    The Declaration Statement

    If you want a variable with a fixed type (e.g. you want a variable to be an integer and to stay an integer whatever comes next) you have to make a declaration statement. A declaraion statement may be one of the following:
                <type> <id> ;
                <type> <id> , <id> , <id> ;
                <type> <id>[] ;
                <type> <id>[<num>,<num>];
    
    Where <type> is one of the following: char, short, int, float, double, complex, string. Each type (except complex and string) is the Xi representation of the corresponding C-type, they will not be explained here. The type complex is basically a complex number which is internally two numbers of type double (the real and imaginary part). You can mostly do the same with a complex number as with a double number. Because Xi does not understand pointers, the string type is the equivalent to char * in C except that you don't have to bother with the memory allocation.

    If you type a [] or [<num>,<num>,...] after the variable name (<id>) Xi will generate an array of <type>. If you only use [] the array is of undefined dimension and the array only consists of one number. On the other hand if you explicitly set the dimension of the array (e.g. double a[10,10] will generate a 10x10 matrix of double numbers).


    © 1995 by Bodo Junglas, Klaus Spanderen and Fabian Weis
    - Last revised: May 30 1996